# -*- coding: utf-8 -*-
# @Time     : 2021/12/1 17:03
# @Author   : wljess
# @File     : GIL锁性能分析.py
# @Describe : 
# @Software : PyCharm

import time
from threading import Thread


def level(num):
    def check_time(func):
        def inner(*args, **kwargs):
            start_time = time.perf_counter()
            func(*args, **kwargs)
            end_time = time.perf_counter()
            if num == 1:
                desc = "普通函数运行时间:"
            else:
                desc = "多线程运行时间:"
            print(f"{desc}{end_time - start_time}")
        return inner
    return check_time


def task(num):
    for i in range(num):
        i += 1


@level(1)
def common_func(num):
    task(num)


@level(2)
def thread_func(num):
    thread_nums = num // 5
    lst_t = []
    for i in range(thread_nums):
        t = Thread(target=task, args=(num // 5, ))
        t.start()
        lst_t.append(t)

    for t in lst_t:
        t.join()


if __name__ == '__main__':
    common_func(10000)
    thread_func(10000)

'''
程序运行结果：
普通函数运行时间:0.000554900000000004
多线程运行时间:0.5025681000000001
'''
